package com.tarena.lbs.content.service.impl;

import com.github.pagehelper.PageInfo;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.common.utils.PageConverter;
import com.tarena.lbs.content.dao.repository.ArticleRepository;
import com.tarena.lbs.content.pojo.param.ArticleActionParam;
import com.tarena.lbs.content.pojo.param.ArticleContentParam;
import com.tarena.lbs.content.pojo.po.ArticleSearchPO;
import com.tarena.lbs.content.pojo.query.ArticleQuery;
import com.tarena.lbs.content.pojo.vo.ArticleActionPageResultVO;
import com.tarena.lbs.content.pojo.vo.ArticleVO;
import com.tarena.lbs.content.service.ArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Repository
@Slf4j
public class ArticleServiceImpl implements ArticleService{
    @Autowired
    private ArticleRepository articleRepository;
    @Override
    public PageResult<ArticleVO> pageList(ArticleQuery query) {
        log.info("查询文章分页列表");
        PageInfo<ArticleSearchPO> pageInfo = articleRepository.pageList(query);
        List<ArticleVO> articleVOS = pageInfo.getList().stream()
                .map(po -> {
                    ArticleVO vo = new ArticleVO();
                    BeanUtils.copyProperties(po, vo);
                    return vo;
                }).collect(Collectors.toList());
        return PageConverter.convert(pageInfo, articleVOS);
    }

    @Override
    public void addArticle(ArticleContentParam param) {
        log.info("保存文章实现层");
        articleRepository.addArticle(param);
    }

    @Override
    public Set<String> articleLabels(ArticleQuery articleQuery) {


        Set<String> set = articleRepository.SetArticle(articleQuery);
        return set;
    }


}
